﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

using MvcEngine.Core.Repositories;
using MvcEngine.Core.Website;
using MvcEngine.Core.Utils;
using System.Web.Configuration;
using MvcEngine.Core.Helpers;

namespace MvcEngine.Core.HttpModules
{
    public class IpBlockHttpModule : BaseHttpModule
    {
        public override void OnBeginRequest(HttpContextBase context)
        {
            var address = WebConfigurationManager.AppSettings["IpBlock"];
            if (!string.IsNullOrEmpty(address) && address != context.Request.UserHostAddress) 
            {
                LogHelper.Current.WriteInfo(context.Request.UserHostAddress + " has tried to reach the site.");
                context.Response.Write("Site is under construction!!!");
                context.Response.End();
            }
        }
    }
}
